package com.lm.framework.data;

import java.util.Collection;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public abstract class DataBaseDao extends HibernateDaoSupport {
	
	public List onLoad(String Hql) {
		List result = null;
		try {
			result = getHibernateTemplate().find(Hql);
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	public void onSaveOrUpdate(Object entity) {
		try {
			getHibernateTemplate().saveOrUpdate(entity);
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void doDelete(Object entity) {
		getHibernateTemplate().delete(entity);
	}

	public void doDeleteAll(Collection entities) {
		getHibernateTemplate().deleteAll(entities);
	}

	public Object loadByObjectId(Class clazz, Integer id) {
		return getHibernateTemplate().get(clazz, id);
	}

	public int onExecuteHQLUpdate(String hql) {
		return getSession().createQuery(hql).executeUpdate();
	}

	public int onExecuteSQLUpdate(String sql) {
		return getSession().createSQLQuery(sql).executeUpdate();
	}

	public List onLoadHQLQuery(String hql) {
		return getSession().createQuery(hql).list();
	}

	public List onLoadSQLQuery(String sql) {
		return getSession().createSQLQuery(sql).list();
	}
}
